import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/login',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: {title: '首页', icon: 'home'}
    }]
  },


  {
    path: '/new',
    component: Layout,
    redirect: '/new/list',
    name: 'New',
    meta: {title: '新闻管理', icon: 'el-icon-s-help'},
    children: [
      {
        path: 'list',
        name: 'List',
        component: () => import('@/views/new/List'),
        meta: {title: '新闻列表', icon: 'table'}
      },
      {
        path: 'addNews',
        name: 'AddNews',
        component: () => import('@/views/new/AddNews'),
        meta: {title: '添加新闻', icon: 'table'}
      },
      {
        path: 'addNews/:newsId',
        name: 'AddNews',
        component: () => import('@/views/new/AddNews'),
        meta: {title: '编辑新闻', noCache: true},
        hidden: true
      },
    ]
  },

  /*学生管理*/
  {
    path: '/student',
    component: Layout,
    redirect: '/student/manage',
    name: 'Student',
    meta: {title: '就业明星', icon: 'el-icon-s-help'},
    children: [
      {
        path: 'manage',
        name: 'ManageStudent',
        component: () => import('@/views/student/ManageStudent'),
        meta: {title: '管理学生', icon: 'table'}
      },
      {
        path: 'addStudent',
        name: 'AddStudent',
        component: () => import('@/views/student/AddStudent'),
        meta: {title: '添加学生', icon: 'table'}
      },
      {
        path: 'addStudent/:id',
        name: 'AddStudent',
        component: () => import('@/views/student/AddStudent'),
        meta: {title: '编辑学生', icon: 'table'},
        hidden: true
      },
      {
        path: 'excel',
        name: 'Excel',
        component: () => import('@/views/student/excel'),
        meta: {title: '批量导入', icon: 'table'},
      },
    ]
  },

  /*教师模块*/
  {
    path: '/teacher',
    component: Layout,
    redirect: '/teacher/list',
    name: 'Teacher',
    meta: {title: '教师管理', icon: 'el-icon-s-custom'},
    children: [
      {
        path: 'list',
        name: 'List',
        component: () => import('@/views/teacher/List'),
        meta: {title: '教师列表', icon: 'table'}
      },
      {
        path: 'add',
        name: 'Add',
        component: () => import('@/views/teacher/Add'),
        meta: {title: '添加教师', icon: 'table'}
      },
      {
        path: 'add/:id',
        name: 'Add',
        component: () => import('@/views/teacher/Add'),
        meta: {title: '编辑教师', icon: 'table'},
        hidden: true
      },
    ]
  },
  /*轮播图*/
  {
    path: '/banner',
    component: Layout,
    redirect: '/banner/manage',
    name: 'Banner',
    meta: {title: '轮播图管理', icon: 'el-icon-picture'},
    children: [
      {
        path: 'manage',
        name: 'Manage',
        component: () => import('@/views/banner/Manage'),
        meta: {title: '轮播图', icon: 'el-icon-picture'}
      },
      {
        path: 'add',
        name: 'Add',
        component: () => import('@/views/banner/Add'),
        meta: {title: '添加图片', icon: 'el-icon-s-promotion'},
        /* hidden: true*/
      },
    ]
  },
  /*校企管理*/
  {
    path: '/project',
    component: Layout,
    redirect: '/project/list',
    name: 'Banner',
    meta: {title: '校企管理', icon: 'el-icon-picture'},
    children: [
      {
        path: 'list',
        name: 'List',
        component: () => import('@/views/project/list'),
        meta: {title: '校企列表', icon: 'el-icon-picture'}
      },
      {
        path: 'add',
        name: 'Add',
        component: () => import('@/views/project/add'),
        meta: {title: '添加校企', icon: 'el-icon-s-promotion'},
        /* hidden: true*/
      },
      {
        path: 'edit/:id',
        name: 'Add',
        component: () => import('@/views/project/add'),
        meta: {title: '编辑校企', icon: 'el-icon-s-promotion'},
        hidden: true
      },
    ]
  },

  {path: '*', redirect: '/404', hidden: true}
]

const createRouter = () => new Router({
  scrollBehavior: () => ({y: 0}),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
